package qf.controller;

import qf.dao.RecordDao;
import qf.dao.daoImpl.RecordDaoImpl;
import qf.pojo.Page;
import qf.pojo.Record;
import qf.service.serviceImpl.RecordServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.controller
 * @Description:
 * @Date 2022/5/27 14:48
 */
@WebServlet("/Record")
public class RecordComtroller extends BaseServlet{
    public String showAll(HttpServletRequest request, HttpServletResponse response){


        RecordDaoImpl recordDao = new RecordDaoImpl();
        RecordServiceImpl recordService = new RecordServiceImpl(recordDao);

        String pageIndex = request.getParameter("pageIndex");

        if(pageIndex == null){
            pageIndex="1";
        }

        int pageindex = Integer.parseInt(pageIndex);
        Page page = new Page(pageindex,5);

        page.setTotalPages(recordService.selectCount(page));

        List<Record> records = recordService.selectAll(page);

        try {
            request.setAttribute("records",records);
            request.setAttribute("page",page);
            request.getRequestDispatcher("/show.jsp").forward(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
return null;
    }

}
